package com.bolao.bets;

import java.util.List;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ListView;

import com.Adapter.RowAdapter;
import com.CustomClasses.InsertMySQL;
import com.bolao.MainTabActivity;
import com.bolao.R;
import com.entidades.BetRow;

public abstract class  BetsFragment extends Fragment {

	protected ListView betsList;
	protected RowAdapter rowAdapter;
	protected Button sendButton;
	private static final String TABLE_NAME = "gen_answ";
	
	
	public RowAdapter getRowAdapter() {
		return rowAdapter;
	}
	protected abstract List<BetRow> getBetRows();

	public View createViewWithBetList(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		
		super.onCreateView(inflater, container, savedInstanceState);
		
	    View view = inflater.inflate(R.layout.bets_fragment, container, false);   
	    
		betsList = (ListView) view.findViewById(R.id.listBets);

		sendButton = (Button) view.findViewById(R.id.sendButton);
		getActivity().setProgressBarVisibility(true);
		rowAdapter = new RowAdapter(getActivity().getApplicationContext(), getBetRows());
		betsList.setAdapter(rowAdapter);
		
		OnClickListener buttonListener = new View.OnClickListener() {
		    @Override
		    public void onClick(View v) {
				    	//UserAnswer.setAnswers(MainTabActivity.getUser().getId(),
				    	//		BetRow.getAllUserBet(getBetRows()), getTableName(), BetRow.getAllColumnNames(getBetRows())); 
		    	new InsertMySQL( TABLE_NAME, BetRow.getAllColumnNames(), MainTabActivity.getUser().getId(), BetRow.getAllUserBet(getBetRows())).execute();
				    }		    
		};
		sendButton.setOnClickListener(buttonListener);	


	    return view;
	}
}
